package com.example.springstudy.myEventBus;

import lombok.SneakyThrows;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.context.ApplicationEvent;
import javax.management.timer.Timer;

/**
 * 自定义的一个事件监听器，监听的对象为
 * {@link StringPublisherEvent} 是一个
 * 继承了{@link ApplicationEvent} 的事件
 *
 *
 * @Auther ZhaoJunZhou
 * @Date 2020/7/22
 */
@Component
public class SecondListner implements ApplicationListener<StringPublisherEvent> {
    /**
     * {@link Async}代表此方法为一个异步的方法
     * 此为在SpringBoot中还需要开启{@link org.springframework.scheduling.annotation.EnableAsync}
     * 这里才会启用
     * @param event
     * @see com.example.springstudy.SpringStudyApplication
     */

    @SneakyThrows
    @Override
    @Async
    public void onApplicationEvent(StringPublisherEvent event) {

        System.out.println(event.getString());

    }
}
